{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "551d6fef",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "045a97e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "10263690",
   "metadata": {},
   "outputs": [],
   "source": [
    "b = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e502a3c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "c = 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a587dafd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a+b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "56debb52",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "22"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a*b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a1979296",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "9f2c7223",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "efba13fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd1 = np.array([[1,2,3],[4,5,6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "bb2ebffc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]] <class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "print(nd1,type(nd1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "49b30abd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd1.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "8e682e7d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd1.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "65ea5aff",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd2 = np.array([['1','2','3'],['4','5','6']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "2a8da743",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['1' '2' '3']\n",
      " ['4' '5' '6']] <class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "print(nd2,type(nd2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "3e02c384",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd2 = nd2.astype(\"int\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "74331697",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "12a6c2ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 3)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "447bad3b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "51f282b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2[0:2:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "0f79fbe2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 3],\n",
       "       [5, 6]])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 切片\n",
    "# nd2[行的切片,列的切片]\n",
    "nd2[0:2:1,1:3:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "cf24ecc5",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd3 = np.array([\n",
    "    [0,1,2,3,4,5],\n",
    "    [10,11,12,13,14,15],\n",
    "   [20,21,22,23,24,25],\n",
    "    [30,31,32,33,34,35],\n",
    "    [40,41,42,43,44,45],\n",
    "    [50,51,52,53,54,55]\n",
    "    ])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "884639be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  5],\n",
       "       [10, 11, 12, 13, 14, 15],\n",
       "       [20, 21, 22, 23, 24, 25],\n",
       "       [30, 31, 32, 33, 34, 35],\n",
       "       [40, 41, 42, 43, 44, 45],\n",
       "       [50, 51, 52, 53, 54, 55]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "60beb4c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd4 = np.array([1,0,1,0,0,1],dtype='bool')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "f70d4928",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True, False,  True, False, False,  True])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "8d2f6b9f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 2, 22, 52])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 布尔索引\n",
    "nd3[nd4,2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "03330985",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([24, 25, 30, 31, 32, 33, 34, 35, 40, 41, 42, 43, 44, 45, 50, 51, 52,\n",
       "       53, 54, 55])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3[nd3>23]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "a8cc1c43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1,  3,  5, 11, 13, 15, 21, 23, 25, 31, 33, 35, 41, 43, 45, 51, 53,\n",
       "       55])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3[nd3%2==1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "2ec66697",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.08231293, -0.05891156, -0.0355102 , -0.01210884,  0.01129252,\n",
       "         0.03469388],\n",
       "       [-0.05034014, -0.03591837, -0.0214966 , -0.00707483,  0.00734694,\n",
       "         0.02176871],\n",
       "       [-0.01836735, -0.01292517, -0.00748299, -0.00204082,  0.00340136,\n",
       "         0.00884354],\n",
       "       [ 0.01360544,  0.01006803,  0.00653061,  0.0029932 , -0.00054422,\n",
       "        -0.00408163],\n",
       "       [ 0.04557823,  0.03306122,  0.02054422,  0.00802721, -0.0044898 ,\n",
       "        -0.0170068 ],\n",
       "       [ 0.07755102,  0.05605442,  0.03455782,  0.01306122, -0.00843537,\n",
       "        -0.02993197]])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linalg.pinv(nd3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "188e0a65",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.        ,  0.84147098,  0.90929743,  0.14112001, -0.7568025 ,\n",
       "        -0.95892427],\n",
       "       [-0.54402111, -0.99999021, -0.53657292,  0.42016704,  0.99060736,\n",
       "         0.65028784],\n",
       "       [ 0.91294525,  0.83665564, -0.00885131, -0.8462204 , -0.90557836,\n",
       "        -0.13235175],\n",
       "       [-0.98803162, -0.40403765,  0.55142668,  0.99991186,  0.52908269,\n",
       "        -0.42818267],\n",
       "       [ 0.74511316, -0.15862267, -0.91652155, -0.83177474,  0.01770193,\n",
       "         0.85090352],\n",
       "       [-0.26237485,  0.67022918,  0.98662759,  0.39592515, -0.55878905,\n",
       "        -0.99975517]])"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sin(nd3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "c087c93a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "294.5833333333333"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.var(nd3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "23bdb3e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17.163430115607234"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(nd3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "e560d7ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 矩阵运算\n",
    "\n",
    "arr1 = np.array([[1,2,3],[4,5,6]])\n",
    "arr2 = np.array([[1,1,1],[1,1,1]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "b6a4ff99",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "7d38fc91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1],\n",
       "       [1, 1, 1]])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "b7631083",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2 3 4]\n",
      " [5 6 7]]\n",
      "[[0 1 2]\n",
      " [3 4 5]]\n",
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "[[1. 2. 3.]\n",
      " [4. 5. 6.]]\n"
     ]
    }
   ],
   "source": [
    "# 对位运算\n",
    "print(arr1+arr2)\n",
    "print(arr1-arr2)\n",
    "print(arr1*arr2)\n",
    "print(arr1/arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "7009194b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1],\n",
       "       [1, 1],\n",
       "       [1, 1]])"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 矩阵的乘法\n",
    "arr3 = np.array([[1,1],[1,1],[1,1]])\n",
    "arr3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "4c08d61d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 6,  6],\n",
       "       [15, 15]])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(arr1,arr3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "abad15a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5, 7, 9],\n",
       "       [5, 7, 9],\n",
       "       [5, 7, 9]])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(arr3,arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "be3ab70f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 6.,  6.],\n",
       "       [15., 15.]])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 矩阵的除法\n",
    "np.dot(arr1,1/arr3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "5d65d54a",
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "ba379cd3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.74360019, 0.27240561, 0.21789134, 0.30060947, 0.52853275,\n",
       "        0.559182  ],\n",
       "       [0.78987004, 0.23072999, 0.71062749, 0.30681861, 0.83461491,\n",
       "        0.34473998],\n",
       "       [0.84071894, 0.45678242, 0.74282803, 0.29718401, 0.69230326,\n",
       "        0.89803396],\n",
       "       [0.6118774 , 0.38927875, 0.02276732, 0.91500598, 0.39729363,\n",
       "        0.32802577]])"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.rand(4,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac2297f6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
